package net.shopxx.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "bmw_task")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "bmw_task_sequence")
public class Task extends BaseEntity{

	private static final long serialVersionUID = 3404567468668181701L;
	
	/**
	 * 订单状态
	 */
	public enum TaskStatus {

		init(0);
		 
	    private int value;
	 
	    private TaskStatus(int num) {
	        this.value = num;
	    }
	 
	    public int toValue() {
	        return value;
	    }
	}
	
	/** 任务标题 */
	private String title;
	
	/** 任务状态 */
	private TaskStatus status;
	
	/** 任务价格 */
	private BigDecimal price;
	
	/** 任务礼品 */
	private List<TaskGift> gifts;
	
	/** 任务记录 */
	private List<TaskRecord> records;
	
	/** 任务要求 */
	private String detail;
	
	/** 发布员 */
	private Member publisher;
	
	/** 操作者 */
	private Member operator;
	
	/** 过期时间 */
	private Date expire;

	@Column(nullable = false)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(nullable = false)
	public TaskStatus getStatus() {
		return status;
	}

	public void setStatus(TaskStatus status) {
		this.status = status;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "bmw_task_gift_mapping")
	public List<TaskGift> getGifts() {
		return gifts;
	}

	public void setGifts(List<TaskGift> gifts) {
		this.gifts = gifts;
	}
	
	@OneToMany(mappedBy = "task", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	public List<TaskRecord> getRecords() {
		return records;
	}

	public void setRecords(List<TaskRecord> records) {
		this.records = records;
	}

	@Column(nullable = false)
	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(nullable = false, updatable = false)
	public Member getPublisher() {
		return publisher;
	}

	public void setPublisher(Member publisher) {
		this.publisher = publisher;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(updatable = false)
	public Member getOperator() {
		return operator;
	}

	public void setOperator(Member operator) {
		this.operator = operator;
	}
	
	public Date getExpire() {
		return expire;
	}

	public void setExpire(Date expire) {
		this.expire = expire;
	}
	

}
